package Solutions

import "sort"

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func getMinimumDifference(root *TreeNode) int {
	sl := dfs_53(root)
	sort.Ints(sl)
	ans := 1<<63 - 1
	for i := 1; i < len(sl); i++ {
		if ans > (sl[i] - sl[i-1]) {
			ans = sl[i] - sl[i-1]
		}
	}
	return ans
}

func dfs_53(root *TreeNode) []int {
	ans := []int{root.Val}
	if root.Left != nil {
		ans = append(ans, dfs_53(root.Left)...)

	}
	if root.Right != nil {
		ans = append(ans, dfs_53(root.Right)...)

	}
	return ans

}
